package com.liuzh.websocket.service.impl;


import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.liuzh.websocket.dao.SQLFile;
import com.liuzh.websocket.dao.SQLService;
import com.liuzh.websocket.model.Staff;
import com.liuzh.websocket.service.LoginService;

@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT,timeout=5)
@Service("loginservice")
@SQLFile(value="login.xml")
public class LoginServiceImpl extends SQLService implements LoginService{
	
	private Staff queryStaffDById(long id) throws Exception {
		
		return (Staff) dao.query(Staff.class, id);
	}
	private Staff queryStaffDByName(String name) throws Exception {
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("@name", name);
		return (Staff) dao.querySqlOne(Staff.class,"SELECT * FROM staff WHERE username = '" + name +"'");
	}
	
	@Override
	public String getpwdbyname(String name) throws Exception {
		Staff s = queryStaffDByName(name);
		if(s!=null)
		return s.getPassword();
		else
		return null;
	}
	@Override
	public Long getUidbyname(String name) throws Exception {
		Staff s= queryStaffDByName(name);
		if(s!=null)
			return (long) s.getStaff_id();
			else
			return null;
	}
	
	@Override
	public String getnamebyid(long id) throws Exception {
		Staff s = queryStaffDById(id);
		if(s!=null)
			return s.getUsername();
			else
			return null;
	}
	
	
	
	
	

}
